﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.ShareData
{
    public class TcmDiseDictService : CrudAppService<TcmDiseDict, TcmDiseDictDto, Guid, TcmDiseDictInput, TcmDiseDictCreateOrUpdateDto, TcmDiseDictCreateOrUpdateDto>
    {
        private IRepository<TcmDiseDict, Guid> _TcmDiseDictRepository;

        public TcmDiseDictService(IRepository<TcmDiseDict, Guid> TcmDiseDictRepository) : base(TcmDiseDictRepository)
        {
            _TcmDiseDictRepository = TcmDiseDictRepository;
        }

        /// <summary>
        /// 获取临床诊断字典列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<TcmDiseDictDto>> GetListAsync(TcmDiseDictInput input)
        {
            var iQuery = await _TcmDiseDictRepository.GetQueryableAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<TcmDiseDict>, List<TcmDiseDictDto>>(iQuery.ToList());

                return new PagedResultDto<TcmDiseDictDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<TcmDiseDict>, List<TcmDiseDictDto>>(items.ToList());

                return new PagedResultDto<TcmDiseDictDto>(totalCount, itemsDto);
            }
        }
    }
}
